#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H

#include <QDialog>

namespace Ui {
class LoginDialog;
}

class QLineEdit;
class QPushButton;

class LoginDialog : public QDialog
{
    Q_OBJECT

public:
    explicit LoginDialog(QWidget *parent = nullptr);
    ~LoginDialog();
private:
    QLineEdit *usernameLineEdit;
    QLineEdit *passwordLineEdit;
    QPushButton *loginButton;
    QPushButton *cancelButton;
    //加密和解密的密钥
    const QByteArray encryptionKey="your_encryption_key";

    void checkAndCreateInitialUser();
    QString hashPassword(const QString &password);
    bool validateUser(const QString &username,const QString &password);
    void saveCredentials(const QString &username,const QString &password);
    bool loadCredentials(QString &username,QString &password);
    QString decryptPassword(const QString &encryptedPassword);

    QString encryptPassword(const QString &password);

    void on_loginButton_clicked();


private:
    Ui::LoginDialog *ui;
};

#endif // LOGINDIALOG_H
